package com.jzt.qf.service.impl;

import com.alibaba.fastjson.JSON;
import com.jzt.qf.beans.HttpResult;
import com.jzt.qf.beans.UploadBase;
import com.jzt.qf.beans.jztBean.InStockPlan_Upload;
import com.jzt.qf.beans.jztBean.LossBill_Upload;
import com.jzt.qf.beans.qfBean.ZxyUploadbillJzt;
import com.jzt.qf.dao.OtherBillDao;
import com.jzt.qf.dao.UploadbillJztDao;
import com.jzt.qf.https.JztApi;
import com.jzt.qf.service.OtherBillServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class OtherBillServerImpl implements OtherBillServer {
    @Resource
    private OtherBillDao otherBillDao;
    @Resource
    private JztApi jztApi;
    @Resource
    private UploadbillJztDao uploadbillJztDao;

    @Override
    public HttpResult uoloadLossBill(String BillCode) {
        log.info("上传报损单BuyBillServiceImpl访问成功");
        List<LossBill_Upload> lossBills = otherBillDao.getLossBill(BillCode);
        log.info("上传报损单数据" + JSON.toJSONString(lossBills));
        HttpResult httpResult = jztApi.HttpRequest(
                new UploadBase("stplOrderPlan", "saveData", lossBills));
        log.info("上传报损单返回数据" + JSON.toJSONString(httpResult));
        if (httpResult.isFlag()) {
            for (LossBill_Upload lossBill : lossBills) {
                ZxyUploadbillJzt zxyUploadbillJzt = new ZxyUploadbillJzt();
                zxyUploadbillJzt.setBillcode(lossBill.getBiz_Bill_No());
                zxyUploadbillJzt.setBilltype(9);
                uploadbillJztDao.updateFlags2(zxyUploadbillJzt);
            }
        }
        return httpResult;
    }

    @Override
    public HttpResult uploadOverflowBill(String BillCode) {
        List<LossBill_Upload> lossBills = otherBillDao.getOverflowBill(BillCode);
        log.info("上传报溢单数据" + JSON.toJSONString(lossBills));
        HttpResult httpResult = jztApi.HttpRequest(
                new UploadBase("stplOrderPlan", "saveData", lossBills));
        log.info("上传报溢单数据" + JSON.toJSONString(httpResult));
        if (httpResult.isFlag()) {
            for (LossBill_Upload lossBill : lossBills) {
                ZxyUploadbillJzt zxyUploadbillJzt = new ZxyUploadbillJzt();
                zxyUploadbillJzt.setBillcode(lossBill.getBiz_Bill_No());
                zxyUploadbillJzt.setBilltype(14);
                uploadbillJztDao.updateFlags2(zxyUploadbillJzt);
            }
        }
        return httpResult;
    }
}
